/**
 * Copyright (c) 2009 Teoti Graphix, LLC See:
 *     http://tkarchitecture.teotigraphix.org
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * @author Michael Schmalle mschmalle@teotigraphix.com
 */
package org.teotigraphix.dx.patterns.manager.model
{

import flash.events.IEventDispatcher;

import org.teotigraphix.dx.core.ToolKitUtil;
import org.teotigraphix.dx.interfaces.IComponentModel;
import org.teotigraphix.dx.interfaces.IComponentModelCore;
import org.teotigraphix.dx.interfaces.IModelLayer;

/**
 * @private
 * 
 * @copyright Teoti Graphix, LLC
 * @author Michael Schmalle
 * @date 07-16-09
 */
public class ModelInfo
{
	include "../../../core/Version.as"
	
	//--------------------------------------------------------------------------
	//
	//  Public Properties
	//
	//--------------------------------------------------------------------------
	
	//----------------------------------
	//  isCore
	//----------------------------------
	
	/**
	 * // TODO DOCME
	 */
	public function get isCore():Boolean
	{
		return (_model is IComponentModelCore);
	}
	
	//----------------------------------
	//  serviceAPI
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _serviceAPI:String;
	
	/**
	 * // TODO DOCME
	 */
	public function get serviceAPI():String
	{
		return _serviceAPI;
	}
	

	//----------------------------------
	//  api
	//----------------------------------
	
	private var _api:Class;

	/**
	 * // TODO DOCME
	 */
	public function get api():Class
	{
		return _api;
	}
	
	/**
	 * @private
	 */
	public function set api(value:Class):void
	{
		_api = value;
		_serviceAPI = ToolKitUtil.getClassName(_api);
	}
	
	
	//----------------------------------
	//  model
	//----------------------------------
	
	private var _model:IComponentModel;

	/**
	 * // TODO DOCME
	 */
	public function get model():IComponentModel
	{
		return _model;
	}
	
	/**
	 * @private
	 */
	public function set model(value:IComponentModel):void
	{
		_model = value;
		_interests = _model.listValueInterests();
	}
	
	//----------------------------------
	//  layer
	//----------------------------------
	
	private var _layer:IModelLayer;

	/**
	 * // TODO DOCME
	 */
	public function get layer():IModelLayer
	{
		if (isCore)
			return null;
		return _layer;
	}
	
	/**
	 * @private
	 */
	public function set layer(value:IModelLayer):void
	{
		_layer = value;
		if (_layer)
			component = _layer.component;
	}
	
	//----------------------------------
	//  serviceAPI
	//----------------------------------
	
	/**
	 * @private
	 */
	private var _interests:Array;
	
	/**
	 * // TODO DOCME
	 */
	public function get interests():Array
	{
		return _interests;
	}
	
	public var component:IEventDispatcher;
	
	//--------------------------------------------------------------------------
	//
	//  Constructor
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	public function ModelInfo()
	{
	}
	
	public function hasInterests():Boolean
	{
		return (_interests != null && _interests.length > 0);
	}
	
	public function isInterest(name:String):Boolean
	{
		if (!hasInterests())
			return false;
		return (_interests.indexOf(name) != -1);
	}
}
}